#ifndef _DEBUGRENDERFEATURE_H_
#define _DEBUGRENDERFEATURE_H_

#include <SERender/Renderer/RenderFeature/RenderFeature.h>
#include <SERender/Entity/Drawable.h>
#include <glm/glm.hpp>
#include <SEngine/Render/Entity/Model.h>
// #include <SEngine/Render/Entity/BoundingGraphics.h>
#include <SECore/ResourcePayload.h>
#include <SEngine/Render/Entity/BoundingBox.h>

namespace SEngine
{
    enum ArrowID
    {
        ARROW_NONE  = 0,
        ARROW_X     = 1,
        ARROW_Y     = 2,
        ARROW_Z     = 3
    };
    class Camera;
    class DebugRenderFeature : public RenderFeature
    {
    public:
        DebugRenderFeature(Renderer & renderer);
        virtual ~DebugRenderFeature() = default;
        virtual void BeginFrame() override;
        virtual void EndFrame() override {}
        void DrawCircle(glm::mat4 model, glm::vec4 color, float lineWidth);
        void DrawLine(glm::vec3 begin, glm::vec3 end, glm::vec4 color, float lineWidth);
        void DrawGrid(float size, float gap, glm::vec4 color, float lineWidth, glm::mat4 model = glm::mat4{1.0f});
        void DrawBox(glm::vec3 pos, glm::vec3 size, glm::vec4 color, float lineWidth, glm::mat4 model = glm::mat4{1.0f});
        void DrawContour(Model & model);
        void DrawModelWithID(Model & model, uint32_t id);
        void DrawIcon(size_t lightHash, glm::mat4 modelMatrix = glm::mat4{1.0f}, float scale = 1.0f);
        void DrawIconID(glm::mat4 modelMatrix = glm::mat4{1.0f}, uint8_t id = 0, float scale = 1.0f);
        // void DrawBoundingGraphics(BoundingGraphics & bounding, glm::vec4 color, float lineWidth);
        void DrawCameraLine(Camera & camera, float width = 1.0f, float height = 1.0f, glm::vec4 color = glm::vec4{1.0f}, float lineWidth = 1.0f);
        void DrawBoundingBox(BoundingBox & box, glm::mat4 model, glm::vec4 color, float lineWidth);

    private:
        void DrawContour(Drawable & drawable);
        void InitCircleDrawable();
        void InitLineDrawable();
        void InitGridDrawable();
        void InitContourMaterial();
        void InitColorIDMaterial();
        void InitIconModel();
        void InitLightTextures();
        void DrawIconImpl(ResRef<Texture> tex, glm::mat4 modelMatrix, float scale);

    private:
        Drawable m_circleDrawable;
        Drawable m_lineDrawable;
        Drawable m_gridDrawable;
        Drawable m_modelIcon;
        ResRef<Material> m_contourMaterial;
        ResRef<Material> m_colorIDMaterial;
        glm::mat4 m_arrowMatrix{1.0f};
        std::unordered_map<size_t, ResRef<Texture>> m_iconTexs;
    };
} // namespace SEngine

#endif